#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> v1(n, vector<int>(m, 0));
	vector<vector<int>> v2(n, vector<int>(m, 0));
	for (int i = 0; i<n; i++)
	for (int j = 0; j<m; j++)
	{
		cin >> v1[i][j];
	}


	for (int i = 1; i<m; i++)
	{
		if (i == 1 && v1[0][i] == 0)
		{
			v2[0][i] = 1;
			continue;
		}
		if (i == 1 && v1[0][i] == 1)
		{
			v2[0][i] = 0;
			continue;
		}
		if (v1[0][i] == 0 && v2[0][i - 1] == 1)
			v2[0][i] = 1;
	}
	for (int i = 1; i<n; i++)
	{
		if (i == 1 && v1[i][0] == 0)
		{
			v2[i][0] = 1;
			continue;
		}
		if (i == 1 && v1[i][0] == 1)
		{
			v2[i][0] = 0;
			continue;
		}
		if (v1[i][0] == 0 && v2[i - 1][0] == 1)
			v2[i][0] = 1;
	}

	for (int i = 1; i<n; i++)
	for (int j = 1; j<m; j++)
	{
		if (v1[i][j] == 1)
			v2[i][j] = 0;
		else{
			v2[i][j] = v2[i - 1][j] + v2[i][j - 1];
		}
	}
	cout << v2[n-1][m-1] << endl;
}